package web.safety.action;

import com.opensymphony.xwork2.ActionSupport;
import domain.entities.*;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import services.*;

import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: vgonzalez
 * Date: 06/09/12
 * Time: 17:50
 * To change this template use File | Settings | File Templates.
 */

@Namespace("/Safety/Tracking")
public class TrackingController extends ActionSupport {
    private List<Droga> drogaList;
    private List<Compromisopais> paisList;
    private DrogaService drogaService;
    private CompromisoPaisService paisService;
    private SafetydocsService safetydocsService;
    private ProtocolCRUDService protocoloService;
    private List<Protocolo> protocoloList;
    private List<DocumentType> tiposDocumentos;
    private List<Safetydocs> list;
    private Droga droga;
    private Protocolo protocolo;
    private String docType;
    private Date fecha;
    private String email;
    private Integer mailId;
    private Compromisopais pais;
    private List<Compromisopais> paises;
    private List<Role> roles;
    private Safetydocs safetydocs;
    private String idVer;

    @Autowired
    public TrackingController(ProtocolCRUDService protocoloService, DrogaService drogaService, CompromisoPaisService paisService, SafetydocsService safetydocsService) {
        this.protocoloService = protocoloService;
        this.drogaService = drogaService;
        this.paisService = paisService;
        this.safetydocsService = safetydocsService;
        this.protocoloList = protocoloService.getProtocols();
        this.tiposDocumentos = DocumentType.getAllTypes();
        this.drogaList = drogaService.getDrogas();
        this.paisList = paisService.findAll();
    }

    @Action(value="main", results={
            @Result(name="success", location="/safety.tracking.search.tiles", type="tiles")
    })
    public String execute() {
        return SUCCESS;
    }

    @Action(value="search", results={
            @Result(name="success", location="/safety.tracking.search.tiles", type="tiles")
    })
    public String search() {
        if(droga != null && droga.getId() != null)
            droga = drogaService.findById(droga.getId());

        if(protocolo != null && protocolo.getId() != null)
            protocolo = protocoloService.findById(protocolo.getId());

        if(pais != null && pais.getId() != null)
            pais = paisService.findById(pais.getId());

        list = safetydocsService.findByFiltros(droga, protocolo, pais, docType, fecha, email, mailId);

        return SUCCESS;
    }

    public List<Droga> getDrogaList() {
        return drogaList;
    }

    public void setDrogaList(List<Droga> drogaList) {
        this.drogaList = drogaList;
    }

    public List<Compromisopais> getPaisList() {
        return paisList;
    }

    public void setPaisList(List<Compromisopais> paisList) {
        this.paisList = paisList;
    }

    public List<Protocolo> getProtocoloList() {
        return protocoloList;
    }

    public void setProtocoloList(List<Protocolo> protocoloList) {
        this.protocoloList = protocoloList;
    }

    public List<DocumentType> getTiposDocumentos() {
        return tiposDocumentos;
    }

    public void setTiposDocumentos(List<DocumentType> tiposDocumentos) {
        this.tiposDocumentos = tiposDocumentos;
    }

    public Compromisopais getPais() {
        return pais;
    }

    public void setPais(Compromisopais pais) {
        this.pais = pais;
    }

    public Protocolo getProtocolo() {
        return protocolo;
    }

    public void setProtocolo(Protocolo protocolo) {
        this.protocolo = protocolo;
    }

    public Safetydocs getSafetydocs() {
        return safetydocs;
    }

    public void setSafetydocs(Safetydocs safetydocs) {
        this.safetydocs = safetydocs;
    }

    public String getDocType() {
        return docType;
    }

    public void setDocType(String docType) {
        this.docType = docType;
    }

    public Date getFecha() {
        return fecha;
    }

    public void setFecha(Date fecha) {
        this.fecha = fecha;
    }

    public List<Role> getRoles() {
        return roles;
    }

    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }

    public List<Compromisopais> getPaises() {
        return paises;
    }

    public void setPaises(List<Compromisopais> paises) {
        this.paises = paises;
    }

    public String getEmail() {
        return email;
    }

    public Droga getDroga() {
        return droga;
    }

    public void setDroga(Droga droga) {
        this.droga = droga;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Integer getMailId() {
        return mailId;
    }

    public void setMailId(Integer mailId) {
        this.mailId = mailId;
    }

    public List<Safetydocs> getList() {
        return list;
    }

    public void setList(List<Safetydocs> list) {
        this.list = list;
    }

    public String getIdVer() {
        return idVer;
    }

    public void setIdVer(String idVer) {
        this.idVer = idVer;
    }
}